//
//  MCAfterSaleDetailFooterView.swift
//  StoreManage
//
//  Created by MC on 2018/2/2.
//  Copyright © 2018年 MC. All rights reserved.
//

import UIKit

class MCAfterSaleDetailFooterView: UIView {

    var self_H = 44 * 4
    var tableView : UITableView?
    
    
    var model : MCAfterSaleListModel = MCAfterSaleListModel() {
        didSet {
            switch model.status {
            case 1: // 待处理
                print("待处理")
            case 2: //
                if model.isRefund == 2 {  // 待退款
                    self.addSubview(logisticsView)
                    logisticsView.snp.remakeConstraints { (make) ->Void in
                        make.left.equalTo(10)
                        make.right.equalTo(0)
                        make.height.equalTo(44)
                        make.bottom.equalTo(timeView.snp.top)
                    }
                    self_H += 44
                    self.frame = CGRect.init(x: 0, y: 0, width: 0, height: self_H)
                    self.tableView?.tableFooterView = self
                }
            case 3: // 待退款
                print("sdf")
            case 4: // 已拒绝
                print("sdf")
                self.addSubview(refuseView)
                refuseView.snp.remakeConstraints { (make) ->Void in
                    make.left.equalTo(10)
                    make.right.equalTo(0)
                    make.height.equalTo(60)
                    make.bottom.equalTo(timeView.snp.top)
                }
                self_H += 60
                self.frame = CGRect.init(x: 0, y: 0, width: 0, height: self_H)
                self.tableView?.tableFooterView = self
            case 5: // 已完成
                print("sdf")
            default:
                break
            }

        }
    }

    
    var imageArray = NSArray() {
     
        
        didSet {
            if imageArray.count > 0 {
                
                imageAreaView.snp.remakeConstraints { (make) ->Void in
                    make.left.bottom.right.equalTo(self)
                    make.height.equalTo(100)
                }
                
                for i in 0..<imageArray.count {
                    let imageView = UIImageView()
                    imageView.contentMode = UIViewContentMode.scaleAspectFill
                    imageView.clipsToBounds = true
                    imageView.sd_setImage(with: URL.init(string: imageArray[i] as! String), placeholderImage: #imageLiteral(resourceName: "Reuse_placeholder_1_1"))
                    imageAreaView.addSubview(imageView)
                    imageView.snp.remakeConstraints { (make) ->Void in
                        make.top.equalTo(explainView.snp.bottom).offset(10)
                        make.size.equalTo(CGSize.init(width: 80, height: 80))
                        make.left.equalTo(self).offset(10 + 90*i)
                    }
                }
                
                self_H += 100
                
                print(self_H)
                self.frame = CGRect.init(x: 0, y: 0, width: 0, height: self_H)
                self.tableView?.tableFooterView = self
            }
        }
    }
    
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.backgroundColor = UIColor.white
        
        self.addSubview(imageAreaView)
        imageAreaView.snp.remakeConstraints { (make) ->Void in
            make.left.bottom.right.equalTo(self)
            make.height.equalTo(0)
        }
        
        
        self.addSubview(explainView)
        explainView.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(10)
            make.right.equalTo(0)
            make.height.equalTo(44)
            make.bottom.equalTo(imageAreaView.snp.top)
        }
        
        self.addSubview(reasonView)
        reasonView.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(10)
            make.right.equalTo(0)
            make.height.equalTo(44)
            make.bottom.equalTo(explainView.snp.top)
        }
        
        self.addSubview(typeView)
        typeView.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(10)
            make.right.equalTo(0)
            make.height.equalTo(44)
            make.bottom.equalTo(reasonView.snp.top)
        }
        
        self.addSubview(timeView)
        timeView.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(10)
            make.right.equalTo(0)
            make.height.equalTo(44)
            make.bottom.equalTo(typeView.snp.top)
        }
    
        
        
        self.frame = CGRect.init(x: 0, y: 0, width: 0, height: self_H)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    lazy var moneyView: MCAfterSaleDetailFooter_moneyView = {
        let view = MCAfterSaleDetailFooter_moneyView()
        return view
    }()
    
    lazy var timeView: MCAfterSaleDetailFooter_itemView = {
        let view = MCAfterSaleDetailFooter_itemView()
        view.nameLabel.text = "订单时间:"
        return view
    }()
    
    lazy var typeView: MCAfterSaleDetailFooter_itemView = {
        let view = MCAfterSaleDetailFooter_itemView()
        view.nameLabel.text = "退款类型:"
        return view
    }()

    lazy var reasonView: MCAfterSaleDetailFooter_itemView = {
        let view = MCAfterSaleDetailFooter_itemView()
        view.nameLabel.text = "退款原因:"
        return view
    }()

    lazy var explainView: MCAfterSaleDetailFooter_itemView = {
        let view = MCAfterSaleDetailFooter_itemView()
        view.nameLabel.text = "退款说明:"
        return view
    }()
    
    lazy var imageAreaView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.white
        return view
    }()

    
    // 已拒绝
    lazy var refuseView: MCAfterSaleDetailFooter_itemView = {
        let view = MCAfterSaleDetailFooter_itemView()
        view.nameLabel.text = "拒绝理由:"
        view.detailLabel.textColor = UIColor.MCMain
        view.detailLabel.textAlignment = NSTextAlignment.left
        return view
    }()
    
    
    // 待退款
    lazy var logisticsView: MCAfterSaleDetailFooter_itemView = {
        let view = MCAfterSaleDetailFooter_itemView()
        view.nameLabel.text = "物流单号:"
        return view
    }()
}
